import { Component, Vue, Inject } from 'vue-property-decorator';

import { IRoomType } from '@/shared/model/room-type.model';
import RoomTypeService from './room-type.service';
import AlertService from '@/shared/alert/alert.service';

@Component
export default class RoomTypeDetails extends Vue {
  @Inject('roomTypeService') private roomTypeService: () => RoomTypeService;
  @Inject('alertService') private alertService: () => AlertService;

  public roomType: IRoomType = {};

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (to.params.roomTypeId) {
        vm.retrieveRoomType(to.params.roomTypeId);
      }
    });
  }

  public retrieveRoomType(roomTypeId) {
    this.roomTypeService()
      .find(roomTypeId)
      .then(res => {
        this.roomType = res;
      })
      .catch(error => {
        this.alertService().showHttpError(this, error.response);
      });
  }

  public previousState() {
    this.$router.go(-1);
  }
}
